package org.ymjava.medical.core.config;

import com.alipay.demo.trade.service.AlipayTradeService;
import com.alipay.demo.trade.service.impl.AlipayTradeServiceImpl;
import org.springframework.boot.context.properties.EnableConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

/**
 * @Description: 支付宝客户端配置
 * @author: yh
 * @date: 2018/8/1 14:07
 */
@Configuration
@EnableConfigurationProperties(AliPayProperties.class)
public class AliPayConfiguration {

    private final AliPayProperties properties;

    public AliPayConfiguration(AliPayProperties properties) {
        this.properties = properties;
    }

    /**
     * alipay-trade-java
     *
     * @return
     */
    @Bean
    public AlipayTradeService alipayTradeService() {
        return new AlipayTradeServiceImpl.ClientBuilder()
            .setGatewayUrl(properties.getOpenApiDomain())
            .setAppid(properties.getAppid())
            .setPrivateKey(properties.getPrivateKey())
            .setAlipayPublicKey(properties.getAlipayPublicKey())
            .setSignType(properties.getSignType())
            .build();
    }

}
